package yesjava;

import java.util.*;
//统计集合中每个元素的 出现的次数
public class Test1 {
    public static void main(String[] args) {
        List<String> list = Arrays.asList(new String[]{"AA", "BB", "AA", "CC", "DD", "BB", "BB", "BB"});
        Map<String, Integer> countMap = new HashMap<>();
        for (String str : list) {
            Integer count = countMap.get(str);
            if (count == null) {
                count = 1;
                countMap.put(str, count);
            } else {
                countMap.put(str, ++count);
            }
        }

        for (String key: countMap.keySet()) {
            System.out.println(key + ":"+ countMap.get(key));
        }

    }
}
